//package com.woniuxy.microsysserver.serurity.config;
//
//import com.woniuxy.microsysserver.serurity.filter.TokenAuthenticationFilter;
//import com.woniuxy.microsysserver.serurity.filter.TokenLoginFilter;
//import com.woniuxy.microsysserver.serurity.security.DefaultPasswordEncoder;
//import com.woniuxy.microsysserver.serurity.security.TokenLogoutHandler;
//import com.woniuxy.microsysserver.serurity.security.TokenManager;
//import com.woniuxy.microsysserver.serurity.security.UnauthorizedEntryPoint;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.data.redis.core.RedisTemplate;
//import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
//import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
//import org.springframework.security.config.annotation.web.builders.HttpSecurity;
//import org.springframework.security.config.annotation.web.builders.WebSecurity;
//import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
//import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
//import org.springframework.security.core.userdetails.UserDetailsService;
//
///*
// * @author: masterhai
// * @date: 2021/2/25:17:48
// * @description:security配置类
// */
//@Configuration
//@EnableWebSecurity
//@EnableGlobalMethodSecurity(prePostEnabled = true)
//public class TokenWebSecurityConfig extends WebSecurityConfigurerAdapter {
//    //查询数据库
//    private UserDetailsService userDetailsService;
//    private TokenManager tokenManager;
//    private DefaultPasswordEncoder defaultPasswordEncoder;
//    private RedisTemplate redisTemplate;
//
//    @Autowired
//    public TokenWebSecurityConfig (UserDetailsService userDetailsService, DefaultPasswordEncoder defaultPasswordEncoder,
//                                   TokenManager tokenManager, RedisTemplate redisTemplate) {
//        this.userDetailsService = userDetailsService;
//        this.defaultPasswordEncoder = defaultPasswordEncoder;
//        this.tokenManager = tokenManager;
//        this.redisTemplate = redisTemplate;
//    }
//
////    @Bean
////    @Override
////    protected AuthenticationManager authenticationManager () throws Exception {
////        return super.authenticationManager();
////    }
////
////    @Autowired//注意这个方法是注入的
////    public void configureGlobal (AuthenticationManagerBuilder auth) throws Exception {
////        auth.userDetailsService(userDetailsService);
////    }
//
//
//    /**
//     * 配置设置
//     *
//     * @param http
//     * @throws Exception
//     */
//    @Override
//    protected void configure (HttpSecurity http) throws Exception {
//        http.exceptionHandling()
//                .authenticationEntryPoint(new UnauthorizedEntryPoint())
//                .and().csrf().disable()
//                .authorizeRequests()
//                .antMatchers("http://my.free.vipnps.vip/payResult","/demo","/pay","/oss/fileUpload","/**/userFont/**","/favicon.ico","/alipay.trade.page.pay-JAVA-UTF-8/**").permitAll()
//                .anyRequest().authenticated()
//                .and().cors()
//                .and().logout().logoutUrl("/admin/acl/index/logout")
//                .addLogoutHandler(new TokenLogoutHandler(tokenManager, redisTemplate)).and()
//                .addFilter(new TokenLoginFilter(authenticationManager(), tokenManager, redisTemplate))
//                .addFilter(new TokenAuthenticationFilter(authenticationManager(), tokenManager, redisTemplate))
//                .httpBasic();
//    }
//
//    /**
//     * 密码处理
//     *
//     * @param auth
//     * @throws Exception
//     */
//    @Override
//    public void configure (AuthenticationManagerBuilder auth) throws Exception {
//        auth.userDetailsService(userDetailsService).passwordEncoder(defaultPasswordEncoder);
//    }
//
//    /**
//     * 配置哪些请求不拦截
//     *
//     * @param web
//     * @throws Exception
//     */
//    @Override
//    public void configure (WebSecurity web) throws Exception {
//        web.ignoring().antMatchers("/api/**","/users/**",
//                "/swagger-resources/**", "/webjars/**", "/v2/**", "/swagger-ui.html/**","/demo","/pay"
//        );
//
////        web.ignoring().antMatchers("/**/userFont/**");
////        web.ignoring().antMatchers("/*/**"
////        );
//    }
//}
